package com.xh.bussiness.exam.controller;

import com.xh.bussiness.exam.bean.dto.PaperTestDto;
import com.xh.bussiness.exam.bean.request.ErrorQuestionPaperTestRequest;
import com.xh.bussiness.exam.bean.request.PaperQuestionTestDetailSaveRequest;
import com.xh.bussiness.exam.bean.request.PaperTestQueryRequest;
import com.xh.bussiness.exam.bean.request.PaperTestSaveRequest;
import com.xh.bussiness.exam.model.PaperQuestionTestDetail;
import com.xh.bussiness.exam.service.IPaperTestService;
import com.xh.bussiness.tiku.bean.request.QuestionQueryRequest;
import com.xh.bussiness.tiku.constant.PaperConstant;
import com.xh.core.bean.AjaxResult;
import com.xh.core.bean.ServiceResultBean;
import com.xh.core.bean.XhPage;
import com.xh.core.constant.AjaxResultConstant;
import com.xh.core.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/*
 * @Author daiwei
 * @Description
 * @Date 2019/4/10 11:33
 **/
@Api(tags="测评-测评相关接口")
@RestController
@RequestMapping("/exam/paperTest")
public class PaperTestController extends BaseController {

    @Autowired
    private IPaperTestService paperTestService;

    @PostMapping("/addRandomPaperTest")
    @ApiOperation("创建随机测试")
    @Transactional
    public AjaxResult addPaperTest(@RequestBody QuestionQueryRequest bean){
        ServiceResultBean<PaperTestDto> result=paperTestService.addRandomNewTest(bean, PaperConstant.TYPE.RANDOM_TEST);
        return new AjaxResult(result.getMsg()==null,result.getMsg(),result.getData());
    }


    @PostMapping("/addPaperTest")
    @ApiOperation("创建测试")
    @Transactional
    public AjaxResult addPaperTest(@RequestBody PaperTestSaveRequest bean){
        ServiceResultBean<PaperTestDto> result=paperTestService.addNewTest(bean);
        return new AjaxResult(result.getMsg()==null,result.getMsg(),result.getData());
    }

    @PostMapping("/submitQuestionAnswer")
    @ApiOperation("提交单题作答结果")
    @Transactional
    public AjaxResult submitQuestionAnswer(PaperQuestionTestDetailSaveRequest bean){
        String msg=paperTestService.addQuestionTestDetail(bean);
        return new AjaxResult(msg==null,msg);
    }

    @PostMapping("/submitTest")
    @ApiOperation("提交测试")
    @Transactional
    public AjaxResult submitTest(@RequestBody List<PaperQuestionTestDetail> details){
    	 return new AjaxResult(AjaxResultConstant.Result.SUCCESS, paperTestService.submitTest(details));
    }

    /**
     * 查询作答结果分页
     * @param page
     * @param bean
     * @return
     */
    @PostMapping("/queryPaperTestPage")
    @ApiOperation("查询作答结果分页")
    public XhPage queryPaperTestPage(XhPage page,PaperTestQueryRequest bean){
        return this.paperTestService.queryPagePaperTest(page,bean);
    }

    /**g'f
     * 查看测评报告
     * @param paperTestId
     * @return
     */
    @PostMapping("/getPaperTestReport")
    @ApiOperation("查看测评报告")
    public AjaxResult getPaperTestReport(String paperTestId){
        return null;
    }

    @PostMapping("/bindUser")
    @ApiOperation("测试结果绑定用户")
    public AjaxResult bindUser(){ return null; }
    
    @PostMapping("/getTestDetailById")
    @ApiOperation("查询题目的答题详情")
    @Transactional
    public AjaxResult getTestDetailById(@RequestBody PaperQuestionTestDetailSaveRequest bean){
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, paperTestService.getTestDetailById(bean));
    }
    
    @PostMapping("/addErrorQuestionPaperTest")
    @ApiOperation("创建错题练习")
    @Transactional
    public AjaxResult addErrorQuestionPaperTest(@RequestBody ErrorQuestionPaperTestRequest bean){
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS,paperTestService.addErrorQuestionPaperTest(bean));
    }

}
